$(function () {

    var changeUrl = '/o2o/local/changelocalpwd';

    var usertype = getQueryString('usertype');

    /**
     * 提交
     */
    $("#submit").click(function () {

        //获取信息
        var userName = $('#userName').val();
        var password = $('#password').val();
        var newPassword = $('#newPassword').val();
        var confirmPassword = $('#confirmPassword').val();

        if (newPassword != confirmPassword) {
            $.toast('两次输入的密码不一致');
            return;
        }

        //添加表单
        var formData = new FormData();
        formData.append('userName', userName);
        formData.append('password', password);
        formData.append('newPassword', newPassword);

        //获取验证码
        var verifyCodeActual = $('#j_captcha').val();
        if (!verifyCodeActual) {
            $.toast('请输入验证码');
            return;
        }
        formData.append('verifyCodeActual', verifyCodeActual);

        //将参数post到后台去修改密码
        $.ajax({
            url: changeUrl,
            type: 'post',
            data: formData,
            contentType: false,
            cache: false,
            processData: false,
            success: function (data) {
                if (data.success) {
                    $.toast('提交成功');
                    if (usertype == 1) {
                        //若用户在前端展示系统页面则自动退回到前端展示系统页面
                        window.location.href = '/o2o/frontend/index';
                    } else {
                        //若用户在自己的店家管理系统则自动退回到店铺列表页中
                        window.location.href = '/o2o/shopadmin/shoplist';
                    }
                } else {
                    $.toast('提交失败!' + data.errMsg);
                    $('#captcha_img').click();
                }
            }
        });
    });

    /**
     * 返回店铺列表页
     */
    $('#back').click(function () {
        window.location.href = '/o2o/shopadmin/shoplist';
    });


})